// pages/goods/goods.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    title_select: 'all',
    pageScrollId: 'all',
    index: 0,
    selectBox: ['all', 'noEvaluate', 'changeBack'],
    canScrollX: true,
    left: 0,
    isMaskShow: false,
  },

  changeTitle(e) {
    this.setData({
      title_select: e.currentTarget.dataset.titleinfo,
    })
  },
  changeToAll() {
    this.setData({
      pageScrollId: 'all',
      title_select: 'all',
      index: 0,
    })
  },
  changeToEvaluate() {
    this.setData({
      pageScrollId: 'noEvaluate',
      index: 1,
      title_select: 'noEvaluate',
    })
  },
  changeToBack() {
    this.setData({
      pageScrollId: 'changeBack',
      title_select: 'changeBack',
      index: 2,
    })
  },
  drawStart(e) {
    this.setData({
      canScrollX: true,
    })
    if (e.target.dataset.noscroll === 'true') {
      this.setData({
        canScrollX: false,
      })
      // 一顿操作
    } else {
      this.setData({
        left: 0,
      })
    }
    this.setData({
      clientX: e.touches[0].clientX,
    })
  },
  drawEnd(e) {
    let value = this.data.clientX - e.changedTouches[0].clientX
    let index = this.data.index
    let selectBox = this.data.selectBox
    if (value > 0) {
      if (index === 2) {
        return
      }
      if (value < 200) {
        this.setData({
          pageScrollId: selectBox[index],
        })
      } else {
        this.setData({
          index: index + 1,
          pageScrollId: selectBox[index + 1],
          title_select: selectBox[index + 1],
        })
      }
    } else {
      if (index === 0) {
        return
      }
      if (value > -200) {
        this.setData({
          pageScrollId: selectBox[index],
        })
      } else {
        this.setData({
          index: index - 1,
          pageScrollId: selectBox[index - 1],
          title_select: selectBox[index - 1],
        })
      }
    }
  },
  deleteStart(e) {
    this.setData({
      deleteClientX: e.touches[0].clientX,
    })
  },
  deleteMove(e) {
    if (this.data.deleteClientX - e.touches[0].clientX >= 30) {
      this.setData({
        left: -164,
      })
    } else if (this.data.deleteClientX - e.touches[0].clientX <= -30) {
      this.setData({
        left: 0,
      })
    }
  },
  // onLoad: function (options) {
  //   wx.hideTabBar({})
  // },

  // 显示蒙版
  maskShow() {
    this.setData({
      isMaskShow: true,
    })
    wx.hideTabBar({})
  },
  // 关闭蒙版
  maskClose() {
    this.setData({
      isMaskShow: false,
    })
  },
})
